package models;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

public class SubjectManagement {
	private final String DRIVER = "org.postgresql.Driver";
	private final String URL = "jdbc:postgresql://localhost:5432/CourseRegistrationSystem";
	private final String SQL_USER = "postgres";
	private final String SQL_PASS = "dkmh";

	Connection connection;
	PreparedStatement ps;
	ResultSet rs;

	public SubjectManagement() throws ClassNotFoundException, SQLException {
		Class.forName(DRIVER);
		connection = DriverManager.getConnection(URL, SQL_USER, SQL_PASS);
	}

	public ArrayList<String> getIdList() throws SQLException {
		ArrayList<String> res = new ArrayList<>();
		String query = "SELECT mamh FROM monhoc";
		ps = connection.prepareStatement(query);
		rs = ps.executeQuery();
		while (rs.next()) {
			res.add(rs.getString("mamh"));
		}
		return res;
	}

	public String getName(String id) throws SQLException {
		String res = "";
		String query = "SELECT tenmh FROM monhoc";
		ps = connection.prepareStatement(query);
		rs = ps.executeQuery();
		while (rs.next()) {
			res = rs.getString("tenmh");
		}
		return res;
	}

	public String getCredit(String id) throws SQLException {
		String res = "";
		String query = "SELECT sotinchi FROM monhoc";
		ps = connection.prepareStatement(query);
		rs = ps.executeQuery();
		while (rs.next()) {
			res = rs.getString("sotinchi");
		}
		return res;
	}

	public String getTGroupId(String id){
		String res ="";
		String query = "";
	}
}
